//
//  MarkViewController.m
//  掌上海印
//
//  Created by admin on 16/4/13.
//  Copyright © 2016年 handsome. All rights reserved.
//

#import "MarkViewController.h"
#import <UIImageView+WebCache.h>
#import "MarkChooseViewController.h"
#import "Util.h"
@implementation MarkViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"待评员工";
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    NSString *path = [[NSBundle mainBundle] pathForResource:@"staff" ofType:@"plist"];
    self.array = [[NSArray alloc] initWithContentsOfFile:path];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _array.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
    
//    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        dispatch_async(dispatch_get_main_queue(), ^{
            [Util setRoundImageView:cell.imageView];
//            [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone];
        });

//    });

    NSDictionary *dic = _array[indexPath.item];
    
    
    [cell.imageView sd_setImageWithURL:[dic objectForKey:@"userImageView"] placeholderImage:[UIImage imageNamed:@"tab_user"]];
    [cell.textLabel setText:[dic objectForKey:@"userName"]];
    [cell.detailTextLabel setText:[dic objectForKey:@"userType"]];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSDictionary *dic = _array[indexPath.item];
    [defaults setObject:dic forKey:@"dic"];
    [defaults synchronize];
    UIStoryboard *story = [UIStoryboard storyboardWithName:@"Forum" bundle:nil];
    MarkChooseViewController *vc = [story instantiateViewControllerWithIdentifier:@"MarkChooseViewController"];
    [self.navigationController pushViewController:vc animated:YES];

    
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    dispatch_async(dispatch_get_main_queue(), ^{
        [Util setRoundImageView:cell.imageView];
        //            [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone];
    });

}


- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = NO;
}

@end
